package com.openbravo.pos.forms;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.ImageIcon;

import com.openbravo.beans.JCalendarDialog;
import com.openbravo.data.basic.BasicException;
import com.openbravo.format.Formats;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

public abstract class SetupSyncProperty extends JDialog {

	private final JPanel contentPanel = new JPanel();
	protected JTextField jTxtStartDate;
	protected JTextField jTxtEndDate;
	protected JCheckBox clientModel;
	protected JCheckBox serviceModel;
	protected JTextArea jMemo;

	/**
	 * Create the dialog.
	 */
	public SetupSyncProperty() {
		setBounds(100, 100, 390, 415);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JLabel label = new JLabel("时间启");
		label.setBounds(20, 29, 54, 15);
		contentPanel.add(label);
		
		jTxtStartDate = new JTextField();
		jTxtStartDate.setBounds(117, 26, 186, 21);
		contentPanel.add(jTxtStartDate);
		jTxtStartDate.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("时间止");
		lblNewLabel.setBounds(20, 57, 54, 15);
		contentPanel.add(lblNewLabel);
		
		jTxtEndDate = new JTextField();
		jTxtEndDate.setBounds(117, 54, 186, 21);
		contentPanel.add(jTxtEndDate);
		jTxtEndDate.setColumns(10);
		
		clientModel = new JCheckBox("分店模式");
		clientModel.setBounds(50, 81, 103, 23);
		contentPanel.add(clientModel);
		
		serviceModel = new JCheckBox("总店模式");
		serviceModel.setBounds(180, 81, 103, 23);
		contentPanel.add(serviceModel);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnDateStartActionPerformed(e);
			}
		});
		btnNewButton.setIcon(new ImageIcon(SetupSyncProperty.class.getResource("/com/openbravo/images/1day.png")));
		btnNewButton.setBounds(307, 25, 44, 22);
		contentPanel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnDateEndActionPerformed(e);
			}
		});
		btnNewButton_1.setIcon(new ImageIcon(SetupSyncProperty.class.getResource("/com/openbravo/images/1day.png")));
		btnNewButton_1.setBounds(307, 53, 44, 23);
		contentPanel.add(btnNewButton_1);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(20, 116, 331, 218);
		contentPanel.add(scrollPane);
		
		jMemo = new JTextArea();
		scrollPane.setViewportView(jMemo);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						doJob();
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						SetupSyncProperty.this.dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
	
	
	public abstract void doJob();
	
	private void btnDateStartActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnDateStartActionPerformed
		Date date;
		try {
			date = (Date) Formats.TIMESTAMP.parseValue(jTxtStartDate.getText());
		} catch (BasicException e) {
			date = null;
		}
		date = JCalendarDialog.showCalendarTimeHours(this, date);
		if (date != null) {
			jTxtStartDate.setText(Formats.TIMESTAMP.formatValue(date));
		}
	}// GEN-LAST:event_btnDateStartActionPerformed

	private void btnDateEndActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnDateEndActionPerformed
		Date date;
		try {
			date = (Date) Formats.TIMESTAMP.parseValue(jTxtEndDate.getText());
		} catch (BasicException e) {
			date = null;
		}
		date = JCalendarDialog.showCalendarTimeHours(this, date);
		if (date != null) {
			jTxtEndDate.setText(Formats.TIMESTAMP.formatValue(date));
		}
	}// GEN-LAST:event_btnDateEndActionPerformed
}
